package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LogInfo;
import com.ruoyi.system.mapper.LogInfoMapper;
import com.ruoyi.system.service.ILogInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author wxd
 * @date 2024-08-01
 */
@Api(value = "日志", tags = {"日志"})
@RestController
@RequestMapping("/system/log")
public class LogInfoController extends BaseController {
    @Autowired
    private ILogInfoService logInfoService;
    @Autowired
    private LogInfoMapper logInfoMapper;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询分页列表")
    @GetMapping("/list")
    public TableDataInfo list(LogInfo logInfo) {
        startPage();
        List<LogInfo> list = logInfoService.selectLogList(logInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogInfo logInfo) {
        List<LogInfo> list = logInfoService.selectLogList(logInfo);
        ExcelUtil<LogInfo> util = new ExcelUtil<LogInfo>(LogInfo.class);
        util.exportExcel(response, list, "日志数据");
    }

    @ApiOperation("查询字段分组列表")
    @Anonymous
    @GetMapping("/fieldGroup")
    public List<String> fieldGroup(String fieldName) {
        return logInfoMapper.selectFieldGroup(fieldName);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{LogID}")
    public AjaxResult getInfo(@PathVariable("LogID") Long LogID) {
        return success(logInfoService.selectLogById(LogID));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增")
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody LogInfo logInfo) {
        logInfo.setId(null);
        return toAjax(logInfoService.insertLog(logInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody LogInfo logInfo) {
        return toAjax(logInfoService.updateLog(logInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除")
    @DeleteMapping("/{LogIDs}")
    public AjaxResult remove(@PathVariable Long[] LogIDs) {
        return toAjax(logInfoService.deleteLogByIds(LogIDs));
    }

    /**
     * 清空
     */
    @ApiOperation("清空")
    @DeleteMapping("/clear")
    public AjaxResult clear() {
        logInfoService.clear();
        return success();
    }
}
